import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isFunction from "lodash/isFunction";

var _dec, _dec2, _dec3, _class;

import React from 'react';
import { Bind } from 'lodash-decorators';
import LeafMenuItem from "./LeafMenuItem";
import styles from "./styles.less?modules";
import { getMenuKey } from "./utils";
var onlySubMenuStyle = {
  height: 53,
  paddingBottom: 13
};
var onlyPrevOnlySubMenuStyle = {
  paddingTop: 12
};
var curAndPrevOnlySubMenuStyle = {
  height: 60,
  paddingBottom: 13,
  paddingTop: 12
};
var emptyStyle = {};
var LeafMenuItemWrap = (_dec = Bind(), _dec2 = Bind(), _dec3 = Bind(), (_class = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(LeafMenuItemWrap, _React$PureComponent);

  var _super = _createSuper(LeafMenuItemWrap);

  function LeafMenuItemWrap() {
    _classCallCheck(this, LeafMenuItemWrap);

    return _super.apply(this, arguments);
  }

  _createClass(LeafMenuItemWrap, [{
    key: "handleLeafMenuClick",
    value: function handleLeafMenuClick(leafMenu) {
      var _this$props = this.props,
          subMenu = _this$props.subMenu,
          onClick = _this$props.onClick;

      if (_isFunction(onClick)) {
        onClick(leafMenu, subMenu);
      }
    }
  }, {
    key: "handleLeafMenuMouseEnter",
    value: function handleLeafMenuMouseEnter() {
      var _this$props2 = this.props,
          subMenu = _this$props2.subMenu,
          onMouseEnter = _this$props2.onMouseEnter;

      if (_isFunction(onMouseEnter)) {
        onMouseEnter(subMenu);
      }
    }
  }, {
    key: "handleLeafMenuMouseLeave",
    value: function handleLeafMenuMouseLeave() {
      var _this$props3 = this.props,
          subMenu = _this$props3.subMenu,
          onMouseLeave = _this$props3.onMouseLeave;

      if (_isFunction(onMouseLeave)) {
        onMouseLeave(subMenu);
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props4 = this.props,
          subMenu = _this$props4.subMenu,
          activeMenus = _this$props4.activeMenus,
          prevSubMenuIsOnlySubMenu = _this$props4.prevSubMenuIsOnlySubMenu;
      var isOnlySubMenu = subMenu.isOnlySubMenu;
      var leafMenuItemWrapStyle = isOnlySubMenu ? prevSubMenuIsOnlySubMenu ? curAndPrevOnlySubMenuStyle : onlySubMenuStyle : prevSubMenuIsOnlySubMenu ? onlyPrevOnlySubMenuStyle : emptyStyle;
      return /*#__PURE__*/React.createElement("div", {
        className: [styles['leaf-menu-item-wrap'], 'cpaas-leaf-menu-item-wrap'].join(' '),
        onMouseEnter: this.handleLeafMenuMouseEnter,
        onMouseLeave: this.handleLeafMenuMouseLeave,
        style: leafMenuItemWrapStyle
      }, isOnlySubMenu ? null : subMenu.children.map(function (leafMenu) {
        return /*#__PURE__*/React.createElement(LeafMenuItem, {
          key: getMenuKey(leafMenu),
          leafMenu: leafMenu,
          active: activeMenus[2] === leafMenu,
          onClick: _this.handleLeafMenuClick
        });
      }));
    }
  }]);

  return LeafMenuItemWrap;
}(React.PureComponent), (_applyDecoratedDescriptor(_class.prototype, "handleLeafMenuClick", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleLeafMenuClick"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleLeafMenuMouseEnter", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "handleLeafMenuMouseEnter"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleLeafMenuMouseLeave", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "handleLeafMenuMouseLeave"), _class.prototype)), _class));
export default LeafMenuItemWrap;